package com.itheima.hmshopping.app.service;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.hmshopping.dubbo.api.SmsHomeAdvertiseApi;
import com.itheima.hmshopping.entity.SmsHomeAdvertise;
import com.itheima.hmshopping.util.HmPage;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SmsHomeAdvertiseService {
    @DubboReference
    private SmsHomeAdvertiseApi smsHomeAdvertiseApi;
    /**
     * 添加广告
     * @param smsHomeAdvertise
     */
    public void create(SmsHomeAdvertise smsHomeAdvertise) {
      smsHomeAdvertiseApi.create(smsHomeAdvertise);

    }

    /**
     * 删除广告
     * @param ids
     */
    public void delete(List<Integer> ids) {

        smsHomeAdvertiseApi.delete(ids);
    }

    /**
     * 分页查询广告
     * @param endTime
     * @param name
     * @param pageNum
     * @param pageSize
     * @param type
     * @return
     */
    public HmPage list(String endTime, String name, Integer pageNum, Integer pageSize, Integer type) {
        Page page= smsHomeAdvertiseApi.list(name,type,pageNum,pageSize,endTime);
        HmPage hmPage=new HmPage();
        //设置总页数
        hmPage.setTotalPage(Convert.toInt(page.getPages()));
        //查询数据
        hmPage.setList(page.getRecords());
        //第几页
        hmPage.setPageNum(Convert.toInt(pageNum));
        //总页数
        hmPage.setTotal(Convert.toInt(page.getTotal()));
        //每页条数
        hmPage.setPageSize(pageSize);
        return hmPage;
    }

    /**
     * 修改上下线状态
     * @param id
     * @param status
     */
    public void updateStatus(Integer id, Integer status) {
        smsHomeAdvertiseApi.updateStatus(id,status);
    }

    /**
     * 修改广告
     * @param id
     * @param smsHomeAdvertise
     */
    public void update(Integer id, SmsHomeAdvertise smsHomeAdvertise) {
        smsHomeAdvertiseApi.update(id,smsHomeAdvertise);
    }

    /**
     * 获取广告详情
     * @param id
     * @return
     */
    public SmsHomeAdvertise getOne(Integer id) {
       return smsHomeAdvertiseApi.getOne(id);
    }
}
